home *** CD-ROM | disk | FTP | other *** search
Wrap
/* * Copyright 1993, 1994, Silicon Graphics, Inc. * All Rights Reserved. * * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.; * the contents of this file may not be disclosed to third parties, copied or * duplicated in any form, in whole or in part, without the prior written * permission of Silicon Graphics, Inc. * * RESTRICTED RIGHTS LEGEND: * Use, duplication or disclosure by the Government is subject to restrictions * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data * and Computer Software clause at DFARS 252.227-7013, and/or in similar or * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished - * rights reserved under the Copyright Laws of the United States. */ #include <stdio.h> #include "exinterfmotif.h" #include <gl.h> #include <string.h> #include <gl/image.h> #include <unistd.h> #include "exbookglo.h" #include "exglobals.h" #include "exinterf.h" extern struct indexlist *add_keyword(); extern struct indexlist *find_keyword(); extern struct grptmpltstruct *find_group_wi_name(); extern unsigned long *readicon_i(); void remove_file(struct filestruct *deadfile); struct filestruct *add_file(char *newfile); void do_iconfiles(struct icntmpltstruct *icnptr); void print_files(); void print_icon_files(struct icntmpltstruct *icn); char inbuf[70]; /************************************************************ * * count the polygons in an icon so that storage can be * allocated all at once. * ************************************************************/ int countpolys(FILE *iconfp) { int bufndx; int polycount; char tmp[20]; int len; /* count the number of polygons */ polycount = 0; while ( fgets(inbuf,60,iconfp) != NULL) { /* find the first char that is not a tab */ bufndx = 0; len = strlen(inbuf); while (bufndx < len+1 && inbuf[bufndx] == '\t') bufndx++; if (inbuf[bufndx] == 'b') { polycount++; /* strncpy(tmp, &(inbuf[bufndx]), 10); if (strncmp(tmp, "bgnoutlinepolygon", 10) == 0) polycount++; */ } } rewind(iconfp); return(polycount); } /************************************************************ * * Print out information about the icons. For debugging. * DO NOT comment out the print statements, look for * calls to print_icons in the rest of the code. * ************************************************************/ print_icons() { struct icntmpltstruct *tmpicn; struct indexlist *kwrd; struct wordlist *wrdptr; struct filelist *adfptr; struct grpliststruct *glist; int i; tmpicn = firsticon; while (tmpicn != NULL) { printf(" Icon Name : %s \n",tmpicn->nameptr->string); /* printf("startstring %s\n",tmpicn->startstring); if (tmpicn->geofile != NULL) printf("filename %s\n",tmpicn->geofile->name); if (tmpicn->imgfile != NULL) printf("filename %s\n",tmpicn->imgfile->name); adfptr = tmpicn->addtlfiles; while ( adfptr!= NULL) { if (adfptr->file != NULL) printf(" file %s \n",adfptr->file->name); adfptr = adfptr->next; } */ printf(" occurs %d num key %d \n",tmpicn->occurences, tmpicn->numkey); if (tmpicn->numkey != 0) { wrdptr = tmpicn->keywords; printf(" keywords: \n"); for (i = 0; i < tmpicn->numkey; i++) { kwrd = wrdptr->indexptr; printf(" %s %d \n",kwrd->string, kwrd->num); wrdptr = wrdptr->next; } } if (tmpicn->grps != NULL) { glist = tmpicn->grps; printf(" groups: \n"); while (glist != NULL) { printf(" %s \n", glist->grpptr->nameptr->string); glist = glist->next; } } tmpicn = tmpicn->nexticntmplt; } } /************************************************************ * * Delete an icon. If this is the last icon on a page, delete * that page, too. If that page was the last one in a * group, delete that group. Currently, If a demo is in the alphabetical group and nowhere else, it can be deleted. This porogram can not go through the other groups and remove references to an iconbefore deleting it. But I think that this will be possible sometime. * ************************************************************/ void deleteicon(thisgroup, iconnum, side) struct grptmpltstruct *thisgroup; int iconnum, side; { int i; struct icntmpltstruct *dead_icon_ptr, *tmpicn, *previcn; struct wordlist *wrdptr, *nextwrd; struct grpliststruct *glistptr, *prevglist; Boolean found, backdone; struct iconstruct *thisiconptr; struct iconstruct *tmpiconptr, *previconptr, *iconhead, *grpiconptr; struct pagestruct *thispage, *tmppg; float org[3], rot[3], ang; struct filelist *tmpfptr; Boolean redraw; redraw = FALSE; previconptr = NULL; if (side == 1) { thispage = rightpage; thisiconptr = thispage->fronticons; } else { thispage = leftpage; thisiconptr = thispage->backicons; } if (iconnum == 0) { if (side == 1) { tmppg = thispage->prevpage; if (tmppg != NULL) { previconptr = tmppg->backicons; redraw = TRUE; } } else previconptr = thispage->fronticons; if (previconptr != NULL) { while (previconptr->nexticon != thisiconptr) { previconptr = previconptr->nexticon; } } } i = 0; while (i != iconnum || (!thisiconptr->ok && Hide)) { if (!Hide || thisiconptr->ok) i++; previconptr = thisiconptr; thisiconptr = thisiconptr->nexticon; } DialogType = 2; sprintf(msgstring,"%s",thisiconptr->iconptr->nameptr->string); popup_Question(); handleMessageEvents(); if(DeleteDemoFlag != TRUE) return; if (thisgroup->nameptr == find_keyword("Master Index") ) { /* take it out of the book completely */ if (thisiconptr->iconptr->occurences == 1) { /* go through the master list of icons and remove this icon from the book */ if (numberoficons == 1) { free(firsticon->startstring); free(firsticon); firsticon = NULL; lasticon = NULL; curicon = NULL; free(firstgroup); firstgroup = NULL; lastgroup = NULL; curgroup = NULL; leftpage = NULL; rightpage = NULL; OPENBOOK = FALSE; resetshelfcolors(); numberofgroups = 0; numberofbooks = 0; numberoficons = 0; currentbook = -1; selected = -1; prevselection = -1; headfile = NULL; /* ERROR is there anything here? */ Index = NULL; drawscene(0); } else { tmpicn = firsticon; if (thisiconptr->iconptr == firsticon) { firsticon = thisiconptr->iconptr->nexticntmplt; } else { while (tmpicn != NULL && tmpicn != thisiconptr->iconptr) { previcn = tmpicn; tmpicn = tmpicn->nexticntmplt; } previcn->nexticntmplt = tmpicn->nexticntmplt; } selected = -1; numberoficons--; dead_icon_ptr = tmpicn; dead_icon_ptr->nameptr->icon = NULL; remove_keyword(dead_icon_ptr->nameptr); delete_keywords( dead_icon_ptr, 0); remove_file(dead_icon_ptr->geofile); remove_file(dead_icon_ptr->imgfile); remove_file(dead_icon_ptr->helpfile); tmpfptr = dead_icon_ptr->addtlfiles; while (tmpfptr != NULL) { remove_file(tmpfptr->file); tmpfptr->file = NULL; tmpfptr = tmpfptr->next; } group_setup(firsticon, 0, thisgroup); } } else /* this demo occurs in other groups in the library */ { sprintf(msgstring, "Because this is an early version of the\ndemobook, demos will not be removed\nfrom the main book while they are\nmembers of other books."); popup_Message(); } } else /* not the alphabetical group */ { (thisiconptr->iconptr->occurences) -= 1; selected = -1; seliconptr = NULL; dead_icon_ptr = thisiconptr->iconptr; /* take reference to this group out of the icon's list of groups */ glistptr = dead_icon_ptr->grps; prevglist = NULL; while (glistptr != NULL && glistptr->grpptr != thisgroup) { prevglist = glistptr; glistptr = glistptr->next; } if (glistptr != NULL) { if (glistptr == dead_icon_ptr->grps) dead_icon_ptr->grps = dead_icon_ptr->grps->next; else if (glistptr->next == NULL) { if (prevglist != NULL) prevglist->next = NULL; } else { prevglist->next = glistptr->next; } free(glistptr); glistptr = NULL; } /* previconptr = thisiconptr; thisiconptr = thisiconptr->nexticon; */ if (thispage != NULL) { if (thispage->prevpage == NULL && thispage->nextpage == NULL && thispage->frontnumicons + thispage->backnumicons == 1) { deletegroup(curgroup); curgroup = NULL; currentbook = -1; OPENBOOK = FALSE; drawscene(0); } else { if (previconptr == NULL) /* only if this is first icon in book */ { if (side == 1) thispage->fronticons = thisiconptr->nexticon; else thispage->backicons = thisiconptr->nexticon; } else previconptr->nexticon = thisiconptr->nexticon; group_setup(NULL, NULL, thisgroup); tmppg = thisgroup->firstpage; if (side == 1) /* front & right */ { while (tmppg != NULL && tmppg != rightpage) tmppg = tmppg->nextpage; if (tmppg == NULL) { leftpage = thisgroup->lastpage; rightpage = NULL; } else { rightpage = tmppg; leftpage = rightpage->prevpage; } } else { while (tmppg != NULL && tmppg != leftpage) tmppg = tmppg->nextpage; if (tmppg == NULL) { rightpage = thisgroup->firstpage; leftpage = NULL; } else { if (tmppg->backnumicons > 0) { leftpage = tmppg; rightpage = leftpage->nextpage; } else { rightpage = tmppg; leftpage = rightpage->prevpage; } } } } } } /*ERROR to delete a demo from the book, need to take it out of all other groups can remove it if it's not present in any other groups */ if (redraw) drawscene(0); if (Indexwin >= 0) update_index_win(); } /************************************************************ * * Given a string, allocate the storage and make it the * startstring for a demo. * ************************************************************/ void set_start_string(iptr,s) struct icntmpltstruct *iptr; char *s; { if (strlen(s) > 0) { iptr->startstring = (char *)malloc(strlen(s)+1); iptr->startstring = strcpy(iptr->startstring, s); } else iptr->startstring = NULL; } void set_alt_command(iptr,s) struct icntmpltstruct *iptr; char *s; { if (strlen(s) > 0) { iptr->alt_command = (char *)malloc(strlen(s)+1); iptr->alt_command = strcpy(iptr->alt_command, s); } else iptr->alt_command = NULL; } fix_icon_ok(struct icntmpltstruct *icnptr) { struct grpliststruct *grplstptr; struct iconstruct *iconptr; struct grptmpltstruct *grpptr; Boolean done; grplstptr = icnptr->grps; while (grplstptr != NULL) { grpptr = grplstptr->grpptr; if (grpptr != NULL) { iconptr = grpptr->firstpage->fronticons; done = FALSE; while(!done && iconptr != NULL) { if (iconptr->iconptr == icnptr) { iconptr->ok = icnptr->ok; done = TRUE; } iconptr = iconptr->nexticon; } } grplstptr = grplstptr->next; } } savedemochanges() { struct icntmpltstruct *icnptr; struct indexlist *tmpptr; struct charlist *charptr, *prevcharptr; struct wordlist *wrdptr, *twrd; int i; Boolean newfile; FILE *iconfp; struct filelist *tmpfptr, *prevfptr; struct filestruct *tmpfs; Boolean indexchange; struct grpliststruct *grplstptr; indexchange = FALSE; selected = -1; icnptr = curicon; if (strcmp(icnptr->nameptr->string, ADName.buf) != 0 ) { indexchange = TRUE; tmpptr = icnptr->nameptr; if (tmpptr != NULL) tmpptr->icon = NULL; remove_keyword(tmpptr); if (ADName.bufpos == 0) if (HeadChar != NULL) icnptr->nameptr = add_keyword(HeadChar->str); else icnptr->nameptr = add_keyword("unknown"); else icnptr->nameptr = add_keyword(ADName.buf); tmpptr = icnptr->nameptr; if (tmpptr != NULL) tmpptr->icon = icnptr; alphabetize(); group_setup(firsticon, NULL, find_group_wi_name("Master Index") ); } if (strcmp(icnptr->startstring, ADCommand.buf) != 0 ) { free(icnptr->startstring); set_start_string(icnptr, ADCommand.buf); } if (icnptr->alt_command != NULL && strcmp(icnptr->alt_command, ADAltCommand.buf) != 0 ) { free(icnptr->alt_command); set_alt_command(icnptr, ADAltCommand.buf); } else if (icnptr->alt_command == NULL) set_alt_command(icnptr, ADAltCommand.buf); if (icnptr->helpfile == NULL && ADHfile.bufpos != 0) icnptr->helpfile = add_file(ADHfile.buf); else if (icnptr->helpfile != NULL && strcmp(icnptr->helpfile->name, ADHfile.buf) != 0 ) { tmpfs = icnptr->helpfile; remove_file(tmpfs); if (ADHfile.bufpos == 0) icnptr->helpfile = NULL; else icnptr->helpfile = add_file(ADHfile.buf); } newfile = 0; if (icnptr->geofile == NULL && ADIfile.bufpos != 0) { icnptr->geofile = add_file(ADIfile.buf); newfile = 1; } else if (icnptr->geofile != NULL && strcmp(icnptr->geofile->name, ADIfile.buf) != 0 ) { tmpfs = icnptr->geofile; remove_file(tmpfs); if (ADIfile.bufpos == 0) icnptr->geofile = NULL; else icnptr->geofile = add_file(ADIfile.buf); newfile = 1; } if (icnptr->imgfile == NULL && ADIfile2.bufpos != 0) { icnptr->imgfile = add_file(ADIfile2.buf); newfile = 1; } else if (icnptr->imgfile != NULL && strcmp(icnptr->imgfile->name, ADIfile2.buf) != 0 ) { tmpfs = icnptr->imgfile; remove_file(tmpfs); if (ADIfile2.bufpos == 0) icnptr->imgfile = NULL; else icnptr->imgfile = add_file(ADIfile2.buf); newfile = 1; } if (newfile) do_iconfiles(icnptr); if (KW_change) { indexchange = TRUE; wrdptr = icnptr->keywords; while (wrdptr != NULL) { remove_keyword_icon(wrdptr->indexptr, icnptr); twrd = wrdptr; wrdptr = wrdptr->next; free(twrd); } icnptr->keywords = NULL; charptr = HeadChar; i = 0; while (charptr != NULL) { if (icnptr->keywords == NULL) { icnptr->keywords=(struct wordlist *)malloc(sizeof(struct wordlist)); wrdptr = icnptr->keywords; } else { wrdptr->next = (struct wordlist *)malloc(sizeof(struct wordlist)); wrdptr = wrdptr->next; } i++; wrdptr->next = NULL; wrdptr->indexptr = add_keyword(charptr->str); index_add_demo(wrdptr->indexptr, icnptr); charptr->indexflag = 1; charptr = charptr->next; } icnptr->numkey = i; KW_change = FALSE; } if (EF_change) { icnptr->ok = TRUE; tmpfptr = icnptr->addtlfiles; /* delete all of the old files */ while (tmpfptr != NULL) { remove_file(tmpfptr->file); tmpfptr->file = NULL; tmpfptr = tmpfptr->next; } /* add all of the files from the interface */ charptr = Head_FL; tmpfptr = icnptr->addtlfiles; prevfptr = NULL; while (charptr != NULL) { if (tmpfptr == NULL) { tmpfptr = (struct filelist *)malloc(sizeof(struct filelist) ); tmpfptr->next = NULL; if (icnptr->addtlfiles == NULL) icnptr->addtlfiles = tmpfptr; } tmpfptr->file = add_file(charptr->str); if (tmpfptr->file != NULL) icnptr->ok = tmpfptr->file->ok; if (prevfptr != NULL) prevfptr->next = tmpfptr; prevfptr = tmpfptr; tmpfptr = tmpfptr->next; free(charptr->str); prevcharptr = charptr->next; free(charptr); charptr = prevcharptr; } /* if I have fewer files now than I used to, delete the unused storage */ if (prevfptr != NULL) prevfptr->next = NULL; while (tmpfptr != NULL) { prevfptr = tmpfptr->next; free(tmpfptr); tmpfptr = prevfptr; } if (Head_FL == NULL) icnptr->addtlfiles = NULL; Head_FL = NULL; Tail_FL = NULL; EF_change = FALSE; /* update ok for all instances of this demo */ fix_icon_ok(icnptr); /* update ok for all the groups that this demo belongs to */ grplstptr = icnptr->grps; while (grplstptr != NULL) { if (grplstptr->grpptr != NULL) fix_grp_ok(grplstptr->grpptr); grplstptr = grplstptr->next; } } if (indexchange && Indexwin >= 0) update_index_win(); } /* new_icn creates a new icon, then zeroes out most of the information * to keep from referencing bogus values. This fixes a bug that Ratman * found where a bogus value in numkey was causing pointers to be * traversed beyond the NULL value. Fixed by Gretch. */ struct icntmpltstruct *new_icn() { struct icntmpltstruct *newicon; int i,j; newicon = (struct icntmpltstruct *) malloc(sizeof(struct icntmpltstruct)); /* now zero EVERYTHING out */ newicon->tex_image = NULL; newicon->tex_id = 0; newicon->tex_width = 0; newicon->tex_height = 0; newicon->poly = NULL; newicon->keywords = NULL; newicon->nameptr = NULL; newicon->infoptr = NULL; newicon->geofile = NULL; newicon->imgfile = NULL; newicon->helpfile = NULL; newicon->addtlfiles = NULL; newicon->nexticntmplt = NULL; newicon->grps = NULL; newicon->xsize = 0; for (i=0; i <4; i++) { for (j=0; j<3; j++) { newicon->bbox[i][j] = 0; } } newicon->numkey = 0; newicon->numpoly = 0; newicon->occurences = 0; newicon->iconnum = 0; newicon->startstring = NULL; newicon->alt_command = NULL; newicon->ok = TRUE; return(newicon); /* return pointer to this info */ } /************************************************************ * * Add a demo to the book. Add it to a group if requested. * Add it to the alphabeitcal group. * ************************************************************/ void add_demo() { struct wordlist *wrdptr; struct charlist *charptr, *prevcharptr; int i; FILE *iconfp; struct icntmpltstruct *newicon, *curicon, *previcon; struct grptmpltstruct *tmpgrp; IMAGE *image; struct filelist *tmpfptr, *lastfile; Boolean done; /*if (ADName.bufpos == 0 && ADCommand.bufpos == 0) don't add */ if (ADName.bufpos != 0 || ADCommand.bufpos != 0)/* if something's there, add */ { if (ADName.bufpos == 0) /* if no name is there, falsify one */ { strcpy(ADName.buf, "No Name"); ADName.bufpos = 8; } lastfile = NULL; /* reset lastfile */ newicon = new_icn(); /* get pointer to icon info */ /* assume the the numberoficons (global) hasn't been incremented yet */ if (firsticon == NULL) /* if not set yet */ { firsticon = newicon; /* this IS the first icon */ lasticon = newicon; /* and the ONLY icon! */ } else /* there are other icons... */ { previcon = NULL; /* we don't know which this is */ curicon = firsticon; /* traverse icons */ while (curicon != NULL && strcmp(ADName.buf,curicon->nameptr->string)>0) { previcon = curicon; curicon = curicon->nexticntmplt; } if (curicon == NULL) { previcon->nexticntmplt = newicon; lasticon = newicon; } else if (curicon == firsticon) { newicon->nexticntmplt = firsticon; firsticon = newicon; } else { previcon->nexticntmplt = newicon; newicon->nexticntmplt = curicon; } } /* redo alphabetical group */ tmpgrp = firstgroup; done = FALSE; while (!done && tmpgrp != NULL) { if (tmpgrp->nameptr == find_keyword("Master Index")) done = TRUE; else tmpgrp = tmpgrp->nextgrp; } if (tmpgrp != NULL) group_setup(firsticon, 0, tmpgrp); newicon->nameptr = add_keyword(ADName.buf); newicon->nameptr->icon = newicon; newicon->occurences = 1; charptr = HeadChar; i = 0; while (charptr != NULL) { if (newicon->keywords == NULL) { newicon->keywords=(struct wordlist *) malloc(sizeof(struct wordlist)); wrdptr = newicon->keywords; wrdptr->next = NULL; } else { wrdptr->next = (struct wordlist *)malloc(sizeof(struct wordlist)); wrdptr = wrdptr->next; wrdptr->next = NULL; } i++; wrdptr->indexptr = add_keyword(charptr->str); index_add_demo(wrdptr->indexptr, newicon); prevcharptr = charptr->next; if (charptr->indexflag == 0) free(charptr->str); free(charptr); charptr = prevcharptr; } newicon->numkey = i; HeadChar = NULL; TailChar = NULL; /* need to make sure this is NULL */ tmpfptr = newicon->addtlfiles; lastfile = NULL; while (tmpfptr != NULL) { lastfile = tmpfptr; tmpfptr = tmpfptr->next; } charptr = Head_FL; while (charptr != NULL) { if (charptr->indexflag == 0) { tmpfptr = (struct filelist *)malloc( sizeof(struct filelist) ); tmpfptr->file = add_file(charptr->str); if (tmpfptr->file != NULL && !tmpfptr->file->ok) newicon->ok = FALSE; tmpfptr->next = NULL; free(charptr->str); if (lastfile == NULL) { newicon->addtlfiles = tmpfptr; lastfile = tmpfptr; } else { lastfile->next = tmpfptr; lastfile = tmpfptr; } } prevcharptr = charptr->next; free(charptr); charptr = prevcharptr; } Head_FL = NULL; Tail_FL = NULL; set_start_string( newicon , ADCommand.buf); set_alt_command( newicon , ADAltCommand.buf); newicon->geofile = NULL; newicon->imgfile = NULL; newicon->helpfile = NULL; newicon->poly = NULL; newicon->tex_image = NULL; newicon->tex_width = 0; newicon->tex_height = 0; newicon->tex_id = -1; if (ADHfile.bufpos > 0) newicon->helpfile = add_file(ADHfile.buf); if (ADIfile.bufpos > 0) newicon->geofile = add_file(ADIfile.buf); if (ADIfile2.bufpos > 0) newicon->imgfile = add_file(ADIfile2.buf); do_iconfiles(newicon); ++numberoficons; } if (Indexwin >= 0) update_index_win(); } /************************************************************ * * The rest of this .c file deals with the files * that the demos need to run. * ************************************************************/ void print_icon_files(struct icntmpltstruct *icn) { struct filelist *tmpfptr; tmpfptr = icn->addtlfiles; while( tmpfptr != NULL) { printf(" file %s \n",tmpfptr->file->name); tmpfptr = tmpfptr->next; } printf("\n"); } void print_files() { struct filestruct *tmpptr; tmpptr = headfile; while (tmpptr != NULL) { printf(" file %s, occurences %d \n",tmpptr->name, tmpptr->occurences); tmpptr = tmpptr->next; } } void check_files() { struct filestruct *tmpptr, *nxtptr; int cmp1, cmp2; tmpptr = headfile; while (tmpptr != NULL) { cmp1 = -5; cmp2 = -5; if (tmpptr->occurences == 0) { nxtptr = tmpptr->next; /* printf(" removing file %s because occurences = 0 \n",tmpptr->name); */ remove_file(tmpptr); tmpptr = nxtptr; } else if ((cmp1 = strncmp(tmpptr->name, "demos/", 6)) == 0 || (cmp2 = strncmp(tmpptr->name, "../", 3))==0) { /* check for demos/something or ../data/demos */ nxtptr = tmpptr->next; tmpptr->occurences = 0; remove_file(tmpptr); tmpptr = nxtptr; } else tmpptr = tmpptr->next; } } /************************************************************ * * Add a file to the file list. * ************************************************************/ struct filestruct *add_file(char *newfile) { struct filestruct *tmpptr, *insert, *curptr; int cmp_result; int length; int acc_ret; tmpptr = NULL; insert = NULL; cmp_result = -1; curptr = headfile; if (curptr != NULL) while (curptr != NULL && (cmp_result=strcmp(newfile, curptr->name)) > 0) { insert = curptr; curptr = curptr->next; } if (cmp_result != 0) /* the file is not in the list */ { tmpptr = (struct filestruct *)malloc( sizeof(struct filestruct) ); length = strlen(newfile); tmpptr->name = (char *)malloc(length +1); tmpptr->name = strcpy(tmpptr->name,newfile); if ((acc_ret = access(tmpptr->name, F_OK)) == 0) tmpptr->ok = TRUE; else tmpptr->ok = FALSE; tmpptr->occurences = 1; tmpptr->written = FALSE; tmpptr->count = 0; tmpptr->icon = NULL; if (headfile == NULL) { headfile = tmpptr; tmpptr->next = NULL; } else if (insert == NULL) { tmpptr->next = headfile; headfile = tmpptr; } else { insert->next = tmpptr; tmpptr->next = curptr; } } else /* the file was in the list */ { tmpptr = curptr; curptr->occurences++; } return(tmpptr); } /************************************************************ * * Remove a file from the file list. * ************************************************************/ void remove_file(struct filestruct *deadfileptr) { struct filestruct *prevptr, *curptr; int cmp_result; if (deadfileptr != NULL) { curptr = headfile; prevptr = NULL; while (curptr != NULL && (cmp_result=strcmp(deadfileptr->name, curptr->name)) > 0) { prevptr = curptr; curptr = curptr->next; } if (cmp_result == 0) { if (curptr->occurences <= 1) { free(curptr->name); curptr->name = NULL; if (curptr == headfile) headfile = curptr->next; else prevptr->next = curptr->next; free(curptr); curptr = NULL; } else curptr->occurences--; } } } /************************************************************ * * The file name pointers in the icon structure have already * been set. THis routine checkes that the files are present. * If the machine does texture mapping, the imgfile will be * read. If that file can not be found, or the machine does * not do texture mapping, the geofile will be used. If a * geofile does not exist or has not been specified, only the * demoname will be drawn. * ************************************************************/ void do_iconfiles(struct icntmpltstruct *icnptr) { FILE *iconfp; char *fname; int ret; iconfp = NULL; if (icnptr->tex_image != NULL) free(icnptr->tex_image); if (icnptr->poly != NULL) free(icnptr->poly); icnptr->tex_image = NULL; icnptr->poly = NULL; icnptr->numpoly = 0; if (getgdesc(GD_TEXTURE) && icnptr->imgfile != NULL) { readicon_i( icnptr); icnptr->xsize = 1.0; icnptr->bbox[0][0] = -.1; icnptr->bbox[0][1] = -.1; icnptr->bbox[0][2] = 0.0; icnptr->bbox[1][0] = 1.1; icnptr->bbox[1][1] = -.1; icnptr->bbox[1][2] = 0.0; icnptr->bbox[2][0] = 1.1; icnptr->bbox[2][1] = 1.1; icnptr->bbox[2][2] = 0.0; icnptr->bbox[3][0] = -.1; icnptr->bbox[3][1] = 1.1; icnptr->bbox[3][2] = 0.0; } /* if the machine doesn't do texture mapping, or there's not a img file, or reading it doesn't work read the WorkSpace icon */ if (icnptr->tex_image == NULL) { if (icnptr->geofile != NULL) { if (demoenv != NULL && strncmp("$DEMOS", icnptr->geofile->name, 6) == 0) { fname = (char *)malloc(demoenvlen + strlen(icnptr->geofile->name) ); strcpy(fname, demoenv); strcpy(&(fname[demoenvlen]), &(icnptr->geofile->name[6])); } else if (xenv != NULL && strncmp("$XDEMOS", icnptr->geofile->name, 7) == 0) { fname = (char *)malloc(xenvlen + strlen(icnptr->geofile->name) ); strcpy(fname, xenv); strcpy(&(fname[xenvlen]), &(icnptr->geofile->name[7])); } else if (sbenv != NULL && strncmp("$SBIN", icnptr->geofile->name, 5) == 0) { fname = (char *)malloc(sbenvlen + strlen(icnptr->geofile->name) ); strcpy(fname, sbenv); strcpy(&(fname[sbenvlen]), &(icnptr->geofile->name[5])); } else { fname = (char *)malloc(1 + strlen(icnptr->geofile->name) ); strcpy(fname, icnptr->geofile->name); } if ( (iconfp = fopen(fname, "r") ) == NULL) { sprintf(msgstring, "\nDemo %s\nCould not open iconfile:\n%s",icnptr->nameptr->string, icnptr->geofile->name); popup_Message(); handleMessageEvents(); icnptr->numpoly = 0; } else { icnptr->numpoly = countpolys(iconfp); icnptr->poly = (struct polylist *) malloc((icnptr->numpoly)*sizeof(struct polylist) ); lastvertex =readicon_g(iconfp,icnptr,lastvertex); } if (iconfp != NULL) { ret = fclose(iconfp); } free(fname); } } }